require 'test_helper'


class ClientTest < ActiveSupport::TestCase
  test "should not save client with missing room name" do
    client = Client.create CLIENT_PARAMS_MISSING_NAME
    assert_predicate client , :new_record?
  end

  test "should not save client with empty room name" do
    client = Client.create CLIENT_PARAMS_EMPTY_NAME
    assert_predicate client , :new_record?
  end

  test "should not save client with missing nicks list" do
    client = Client.create CLIENT_PARAMS_MISSING_NICKS
    assert_predicate client , :new_record?
  end

  test "should not save client with empty nicks list" do
    client = Client.create CLIENT_PARAMS_EMPTY_NICKS
    assert_predicate client , :new_record?
  end

  test "should not save client with missing client type" do
    client = Client.create CLIENT_PARAMS_MISSING_TYPE
    assert_predicate client , :new_record?
  end

  test "should not save client with empty client type" do
    client = Client.create CLIENT_PARAMS_EMPTY_TYPE
    assert_predicate client , :new_record?
  end

  test "should save client with valid params" do
    client = Client.create CLIENT_C_PARAMS_VALID
    assert_not_predicate client , :new_record?
    assert_not_nil       client.room
    assert_kind_of       Client , client
  end

  test "should not save client with duplicate channel name" do
    assert_raises ActiveRecord::RecordNotUnique do
      client = Client.create CLIENT_A_PARAMS_VALID
    end
  end

# TODO: ensure Room is destroyed upon destruction of it's only associated Client
# TODO: ensure messages are dependent-destroyed upon destruction of their Room
end
